import threading

consoleWriter = None

def initialize_console():
	consoleWriter = ConsoleWriter()
	
def finalize_console():
	consoleWriter = None
	
class ConsoleWriter(object):
	def __init__(self):
		self._consoleLock = threading.Lock()
		
	def write(self, s):
		self._consoleLock.acquire()
		print s
		self._consoleLock.release()

# helper function
def cwrite(s):
	if consoleWriter is not None:
		consoleWriter.write(s)
	else:
		print s

def cnotify(s):
	cwrite(s)

def csay(s, name):
	cwrite("\"{0}\" says {1}.".format(s, name))

def cmessage(player, s):
	player.message(s)
